-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovieDAO.java
More file actions
51 lines (42 loc) · 1.26 KB
/
MovieDAO.java
File metadata and controls
51 lines (42 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package at.htl.MovieManager.business;
import at.htl.MovieManager.model.Movie;
import javax.enterprise.context.ApplicationScoped;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.transaction.Transactional;
import java.util.List;
@ApplicationScoped
public class MovieDAO {
@PersistenceContext
EntityManager em;
@Transactional
public Movie persist(Movie entity){
em.persist(entity);
return entity;
}
public List<Movie> getAll(int offset, int limit) {
TypedQuery<Movie> query = em.createNamedQuery("Movie.findAll",Movie.class);
query.setFirstResult(offset);
query.setMaxResults(limit);
return query.getResultList();
}
public Movie getById(long id) {
TypedQuery<Movie> query = em.createNamedQuery("Movie.findById",Movie.class);
query.setParameter("Id",id);
return query.getSingleResult();
}
public Movie find(Class<Movie> movieClass, long id)
{
//movieClass = Movie.class
return em.find(movieClass,id);
}
public Movie merge(Movie entity)
{
return em.merge(entity);
}
public void remove(Movie entity)
{
em.remove(entity);
}
}